﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CTMOES;
using CTMOES.Models;

namespace CTMOES.DAL
{
    /// <summary>
    /// 问题的数据访问器
    /// </summary>
    public class QuestionProvider
    {
        /// <summary>
        /// 数据库上下文
        /// </summary>
        private static readonly CTMDBEntities _db = new CTMDBEntities();

        /// <summary>
        /// 获取问题
        /// </summary>
        /// <param name="Category">试题分类ID</param>
        /// <returns>问题集合</returns>
        public static List<QueModel> GetQueList(int Category,Guid sID,int count)
        {
            var questions = _db.Question.Where(q => q.Category == Category && q.Subject == sID).ToList().Take(count);
            List<QueModel> QueList = new List<QueModel>();
            QueModel tmp;
            int num = 1;
            foreach (var question in questions)
            {
                tmp = new QueModel();
                tmp.ID = question.ID;
                tmp.Category = Convert.ToInt32(question.Category);
                tmp.ProContent = num.ToString()+". "+question.ProContent;
                tmp.OptionList = OptionProvider.GetOptions(tmp.ID);
                num++;
                QueList.Add(tmp);
            }
            return QueList;
        }
    }
}